/*
 * Powered By free
 * Web Site: 
 * Since 2018 - 2021
 */
package com.menhai.personmanagement.services;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
/**
 * @author free
 * @version 1.0
 * @since 2021/12/06 09:22
 */
import com.menhai.personmanagement.entity.MbIndexInput;
import com.menhai.personmanagement.entity.MbPopulation;
import com.menhai.personmanagement.mapper.MbIndexInputMapper;

@Service
public class MbIndexInputService {
	
	 @Autowired
	 private MbIndexInputMapper mbIndexInputMapper;

  	@Transactional
  	public Map<String, Object> addMbIndexInput(MbIndexInput mbIndexInput) {
  		Map<String,Object> resultMap = new HashMap<String,Object>();
  		try{
  			//1，新建随访记录
  			int iRet = mbIndexInputMapper.insert(mbIndexInput);
  			if(iRet == 0){  //没有插入成功的数据
  				resultMap.put("success", "0");
  				resultMap.put("message", "插入成功的条数为0，新建每日健康体征记录失败！");
  				return resultMap;
  			}else{
  				resultMap.put("success", "1");
  				resultMap.put("message", "新建每日健康体征记录成功！");
  				return resultMap;
  			}
  		}catch(Exception e){
  			resultMap.put("success", "0");
  			resultMap.put("message", "新建每日健康体征记录失败！异常：" +e.getMessage());
  			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  		}
  		return resultMap;
  	}
  	
  	@Transactional
  	public Map<String, Object> editMbIndexInput(MbIndexInput mbIndexInput) {
  		Map<String,Object> resultMap = new HashMap<String,Object>();
  		try{
  			//1，编辑随访记录
  			int iRet = mbIndexInputMapper.update(mbIndexInput);
  			if(iRet == 0){  //没有插入成功的数据
  				resultMap.put("success", "0");
  				resultMap.put("message", "编辑成功的条数为0，编辑每日健康体征记录失败！");
  				return resultMap;
  			}else{
  				resultMap.put("success", "1");
  				resultMap.put("message", "编辑每日健康体征记录成功！");
  				return resultMap;
  			}
  		}catch(Exception e){
  			resultMap.put("success", "0");
  			resultMap.put("message", "编辑每日健康体征记录失败！异常：" +e.getMessage());
  			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
  		}
  		return resultMap;
  	}
  	

	@Transactional
	public Map<String, Object> deleteById(String id) {
		Map<String,Object> resultMap = new HashMap<String,Object>();
		try{	
			//删除随访记录信息
			int iRet = mbIndexInputMapper.delete(id);
			if(iRet == 0){  
				resultMap.put("success", "0");
				resultMap.put("message", "删除成功的条数为0，删除每日健康体征记录失败！");
				return resultMap;
			}
			resultMap.put("success", "1");
			resultMap.put("message", "删除每日健康体征记录成功！");
		}catch(Exception e){
			resultMap.put("success", "0");
			resultMap.put("message", "删除每日健康体征记录失败！异常：" +e.getMessage());
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
		}
		return resultMap;
	}
	

	public List<Map<String,Object>> getListByCondition(MbIndexInput mbIndexInput) {
		return mbIndexInputMapper.getListByCondition(mbIndexInput);
	}
	
	
	public IPage<MbIndexInput> getListByConditionByPage(MbIndexInput mbIndexInput){
        Page<MbIndexInput> page = new Page<>(mbIndexInput.getPageIndex(),mbIndexInput.getPageSize());
        return mbIndexInputMapper.getListByConditionByPage(page,mbIndexInput);
    }
	
	/**
	 * 获取随访记录列表
	 * @param getOneById
	 * @return List<Map>
	 */
	public List<Map<String,Object>> getOneById(MbIndexInput mbIndexInput) {
		return mbIndexInputMapper.getOneById(mbIndexInput);
	}


	public List<Map<String,Object>> getOneByPopulation(String populationId) {
		return mbIndexInputMapper.getOneByPopulation(populationId);
	}
	
}
